<?php
error_reporting(E_ALL ^ E_NOTICE);

set_time_limit(0);
$db_name="dinocap2";  
 
$table_name="dinocap2hd";  
 
$connection= @mysql_connect("localhost","root","root") or die(mysql_error());  
 
$db= @mysql_select_db($db_name,$connection) or die (mysql_error());  
 
$deviceid_query =  mysql_query("SELECT DISTINCT deviceid,firstlogin FROM dinocap2hd where isjailBreak = '0'");

while($deviceid = mysql_fetch_array($deviceid_query))
{
     //进入游戏次数
    $playNum_query = mysql_query("SELECT count(1) FROM dinocap2hd where deviceid = $deviceid[deviceid]");

    $playNum = mysql_fetch_array($playNum_query);

     //总游戏时间
    $TotalGameTime_query = mysql_query("SELECT totalTime FROM dinocap2hd_last where deviceid = $deviceid[deviceid]");
    $TotalGameTime = mysql_fetch_array($TotalGameTime_query);

    //最后停留等级
    $level_query = mysql_query("SELECT player1Level,player2Level,player3Level,player4Level,player5Level FROM dinocap2hd_last where deviceid = $deviceid[deviceid]");
    $level = mysql_fetch_array($level_query);

    //成活率 Survival
    $Survival_query = mysql_query("SELECT  count(1)
FROM dinocap2hd
WHERE isjailbreak = '0' and whatday > DATE_ADD( '$deviceid[firstlogin]', INTERVAL 7
DAY )
and  deviceid = '00039dff0d2f7c1331c20623f9b3d6b3e033edef'");
    $Survival = mysql_fetch_array($Survival_query);

$sql = "UPDATE report_nojailbreak_total SET playNum= '$playNum[0]' WHERE deviceid= '$deviceid[deviceid]'";
$sql2 = "UPDATE report_nojailbreak_total SET TotalGameTime= '$TotalGameTime[0]' WHERE deviceid= '$deviceid[deviceid]'";
$sql3 = "UPDATE report_nojailbreak_total SET Survival= '$Survival[0]' WHERE deviceid= '$deviceid[deviceid]'";
$sql4 = "UPDATE report_nojailbreak_total SET level= '$level[0]' WHERE deviceid= '$deviceid[deviceid]'";
$sql5 = "UPDATE report_nojailbreak_total SET player2Level= '$level[2]' WHERE deviceid= '$deviceid[deviceid]'";
$sql6 = "UPDATE report_nojailbreak_total SET player3Level= '$level[3]' WHERE deviceid= '$deviceid[deviceid]'";
$sql7 = "UPDATE report_nojailbreak_total SET player4Level= '$level[4]' WHERE deviceid= '$deviceid[deviceid]'";
$sql8 = "UPDATE report_nojailbreak_total SET player5Level= '$level[5]' WHERE deviceid= '$deviceid[deviceid]'";

if(mysql_query($sql,$conn)){
    echo "1 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql2,$conn)){
    echo "2 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql3,$conn)){
    echo "3 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql4,$conn)){
    echo "4 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql5,$conn)){
    echo "5 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql5,$conn)){
    echo "6 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql6,$conn)){
    echo "7 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql7,$conn)){
    echo "8 update is ok!";
} else {
    echo "failed：".mysql_error();
}
}
?>
